#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

// int main(){
//     char a[10] = "aaaaaaaaaa";
//     a[9] = '\0';
//     printf("%s\n",&a[5]); 

// }
int main()
{
    int fd = open("/proc/jihaixuan", O_RDWR);
    if (fd < 0)
    {
        printf("fd open error\n");
        exit(1);
    }
    char write_buf [] = "123456789012345678901234567890";
    int write_count = write(fd,write_buf,30);
    if(write_count<0){
        printf("write error\n");
        exit(1);
    }
    printf("write count %d\n",write_count);
    off_t offset  = lseek(fd,4,SEEK_SET);
    printf("set offset %ld\n",offset);
    for (int i = 0; i < 5; i++)
    {
        /* code */
        char buf[10] = {0};
        int read_count = read(fd, buf, 5);
        if (read_count < 0)
        {
            printf("read error\n");
            exit(1);
        }
        buf[read_count] =0;
        printf("read times %d \n",i);
        for(int j=0;j<read_count;j++){
            printf("%3d  ",buf[j]);
        }
        printf("\n");
        printf("%s\n",buf);
        
    }

   
}